package com.six.business.controller;

import com.six.business.service.CheckBusinessService;
import com.six.business.vo.BusinessVo;
import com.six.business.vo.CheckBusinessVo;
import com.six.core.entity.CheckBusiness;
import com.six.core.util.JwtUtil;
import com.six.core.util.WebUtil;
import com.six.core.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author: WangPeng
 * @createTime: 2023/02/28 14:00
 * @description:
 * @version: v1.0
 */
@Api(value = "/business/checkBusiness", tags = {":"})
@RestController
@RequestMapping("/business/checkBusiness")
public class CheckBusinessController {
    @Autowired
    private CheckBusinessService checkBusinessService;


    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "currentPage", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "", required = true),
            @ApiImplicitParam(paramType = "body", dataType = "CheckBusinessVo", name = "checkBusinessVo", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("/findAll")
    public Result findAll(int currentPage, int pageSize, @RequestBody CheckBusinessVo checkBusinessVo){
        System.out.println(checkBusinessVo.getSearchStart());
        System.out.println(checkBusinessVo.getSearchEnd());
        System.out.println(checkBusinessVo.getState());
        return checkBusinessService.getCheckBusinessList(currentPage,pageSize,checkBusinessVo);
    }

    /** 入驻审核 */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "CheckBusiness", name = "checkBusiness", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("/setBusinessState")
    public Result setBusinessState(@RequestBody CheckBusiness checkBusiness){
        return checkBusinessService.setBusinessState(checkBusiness);
    }

    /** 前台获取商家入驻审核状态接口  /business/checkBusiness/getCheckBusinessState*/
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("/getCheckBusinessState")
    public Result getCheckBusinessState(){
        HttpServletRequest request = WebUtil.getRequest();
        String token = request.getHeader("token");
        if(token != null){
            Map<String, Object> map = JwtUtil.decodeJWT(token);
            Integer userid = (Integer) map.get("tbUserid");
            return checkBusinessService.getCheckBusinessState(userid);
        }
        return new Result(201,"请先登录");
    }

}
